import * as server from '../server/base.js'
import { arrayToTree } from '@/tools'
import router from '@/router'
import Vue from 'vue'
import state from '../state.js'

export default {
    namespaced: true,
    state: {
        sysUser: '',
        userId: '',
        organizationId: '',// 组织机构id
        meun: {},
        sysMenuFuncs: [],
        layoutData: [],
        permissions:[],
        firstMenu:"",
        functionList: [],
        userInfo: {},
        
    },
    mutations: {
        SET_LAYOUT_DATA: (state, { layoutData}) => {
            Vue.set(state, 'layoutData', layoutData)
            console.log('base.js-------------layoutData',state.layoutData)
        },
        SET_USER_INFO: (state, { userInfo }) => {
            Vue.set(state, 'userId', userInfo.uid)
        },
        SET_FUNCTION_AUTHORITY: (state, {functionList}) => {
            Vue.set(state, 'functionList', functionList)
        },
        
    },
    actions: {
        // 获取登录的手机验证码
       
        // 获取侧边框数据
        async getLayoutData({ commit }, { jobId }) {
            let layoutData = JSON.parse(localStorage.getItem('layoutData'))
            commit('SET_LAYOUT_DATA', {
                layoutData: layoutData,
            })
            return menuList
        },
        // 获取用户信息
        async login({ commit }, loginUser) {
            const userInfo = await server.login(loginUser)
            if(userInfo.code !=200){ return userInfo}
            console.log('userInfo',userInfo)
            window.localStorage.setItem('user_token', userInfo.data.token)
            commit('SET_LAYOUT_DATA', {
                layoutData: userInfo.data.permissionRespList,
            })
            // console.log('isLogin11',localStorage.token)
            localStorage.setItem('layoutData', JSON.stringify(userInfo.data.permissionRespList))
            return userInfo 
        },
        // 获取编辑页面的数据
        async getDetailsData({ commit }, { url, queryData }){
            // const data = await commit('SET_USER_INFO', { userInfo })
            // return data
        },
        // 切换页面时的回调
        // async switchPage({ commit }, { menuId }) {
        //     await commit('SET_FUNCTION_AUTHORITY', {functionList: this.state.base.sysMenuFuncs.filter(item => item.menuId === menuId)})
        // },

    },
}
